//
//  MYGHealthManagementNormalTextCell.swift
//  MYGrow
//
//  Created by 林矗 on 2024/3/9.
//

import UIKit

class MYGHealthManagementNormalTextCell: MYGHealthManagementBaseCell {
    // MARK: - Property
    override var model: MYGHealthManagementRowModel? {
        didSet {
            guard let model = (model as? MYGHealthManagementNormalTextModel) else { return }
            titleLabel.text = model.localEventType.name
            contentLabel.text = model.localEventType.content
        }
    }
    
    // MARK: - init
    override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
        super.init(style: style, reuseIdentifier: reuseIdentifier)
        selectionStyle = .none
        contentView.backgroundColor = .white
        configUI()
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    // MARK: - UI
    private func configUI() {
        addSubviews([
            titleLabel,
            contentLabel,
            arrowIcon,
            separator
        ])
        
        titleLabel.snp.makeConstraints { make in
            make.left.equalTo(22.5)
            make.centerY.equalToSuperview()
            make.width.lessThanOrEqualTo(screenWidth-130)
        }
        
        arrowIcon.snp.makeConstraints { make in
            make.right.equalTo(-35)
            make.centerY.equalToSuperview()
            make.size.equalTo(CGSize(width: 7, height: 12))
        }
        
        contentLabel.snp.makeConstraints { make in
            make.top.equalTo(20)
            make.left.greaterThanOrEqualTo(titleLabel.snp.right).offset(20)
            make.right.equalTo(arrowIcon.snp.left).offset(-5)
            make.bottom.equalTo(-20)
            make.height.greaterThanOrEqualTo(20)
        }
        
        separator.snp.makeConstraints { make in
            make.bottom.equalToSuperview()
            make.left.equalTo(22.5)
            make.right.equalTo(-35)
            make.height.equalTo(0.5)
        }
        
        titleLabel.setContentCompressionResistancePriority(.defaultHigh, for: .horizontal)
        contentLabel.setContentCompressionResistancePriority(.defaultLow, for: .horizontal)
    }
    // MARK: - lazy load
    private lazy var titleLabel: UILabel = {
        let label = UILabel()
        label.font = .regular(14)
        label.textColor = .rgba(43, 43, 43)
        return label
    }()
    
    private lazy var contentLabel: UILabel = {
        let label = UILabel()
        label.font = .regular(14)
        label.textColor = .rgba(43, 43, 43)
        label.numberOfLines = 0
        return label
    }()
    
    private lazy var arrowIcon: UIImageView = {
        let imageV = UIImageView(image: UIImage(named: "Common/right"))
        return imageV
    }()
    
    private lazy var separator: UIView = {
        let view = UIView()
        view.backgroundColor = .rgba(238, 238, 238)
        return view
    }()
    
}
